/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VistaCliente.java
 *
 * Created on 21/01/2010, 01:35:29 AM
 */

package com.imptec.reportfly.view;

import com.imptec.reportfly.Util.*;
import com.imptec.reportfly.model.Cliente;
import com.imptec.reportfly.service.ClienteService;
import com.imptec.reportfly.service.ClienteServiceImpl;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.Connection;
import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;
import org.openswing.swing.mdi.client.InternalFrame;


/**
 *
 * @author Administrador
 */
public class VistaClienteFrame extends InternalFrame {
    private Connection con;
    


    /** Creates new form VistaCliente */
    public VistaClienteFrame() {
        initComponents();
        pintarTabla();
        
       // setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tabla = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        tabla.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Codigo", "Nombre", "Ruc"
            }
        ));
        jScrollPane1.setViewportView(tabla);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 13));
        jLabel1.setForeground(new java.awt.Color(255, 0, 0));
        jLabel1.setText("Lista de Estaciones Ingresados");

        jButton1.setText("Salir");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 683, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 329, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
salir(evt);      // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
  private void pintarTabla(){
  System.out.println("se llamo a pintar tabla");
  String[] titulo=new String[]{"Codigo","Nombre","Direccion"};

  //LENAR DE DATOS EL MODELO
  //la lista
        ClienteService serv=new ClienteServiceImpl();
        ArrayList<Cliente> listat=new ArrayList<Cliente>();
       // TecnicoBean t=new TecnicoBean();
        try {
            
            con=new CrearConexiones().abrir();
            listat=serv.obtenerLista(con);

        } catch (Exception ex) {

        }

  //recuperar la lista
  Object[][] arre=new Object[listat.size()][5];
  int i=0;
  for(Cliente t:listat){
      arre[i][0]=t.getCodigo();
      arre[i][1]=t.getNombre();
      arre[i][2]=t.getRuc();
      i++;
  }


  tabla.addMouseListener(new MouseAdapter()
   {
            @Override
      public void mouseClicked(MouseEvent e)
      {
         int fila = tabla.rowAtPoint(e.getPoint());
         int columna = tabla.columnAtPoint(e.getPoint());
         if ((fila > -1) && (columna > -1))
            System.out.println(tabla.getValueAt(fila,0));
            String valor=(String) tabla.getValueAt(fila,0);
            String x=String.valueOf(valor);
           // FrameClienteM.jcodigo.setText(x);
            setVisible(false);
      }
   });
  DefaultTableModel modelo=new DefaultTableModel(arre, titulo);
  //ASIGNAR EL MODELO A LA TABLA
  tabla.setModel(modelo);
  //ASIGNAR LA TABLA SCROOLPANEL
  jScrollPane1.setViewportView(tabla);
  /*

        tabla.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Producto", "Cantidad", "Precio"
            }
        ));
        jScrollPane1.setViewportView(tabla);

   * */
}
  /*  public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VistaCliente().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tabla;
    // End of variables declaration//GEN-END:variables
 private void salir (java.awt.event.ActionEvent evt){
       actionPerformed(evt);
   }

    private void actionPerformed(ActionEvent evt) {
        setVisible(false);
        dispose();
    }
 
}
